/**
 * Helper Game Activity.
 *
 * Released under Apache License, Version 2.0.
 */

package bsp.andengine;

import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuItem;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.ui.activity.BaseGameActivity;

public abstract class HelperGameActivity extends BaseGameActivity
{
	protected static final int MENU_TRACE = Menu.FIRST;
	
	protected Camera mCamera;
	protected int mCameraWidth, mCameraHeight;
	protected float mCenterX, mCenterY;
	protected Scene mScene;
	protected Object mObjSynchronize;
	protected int mGameState;
	protected long mStartTime, mEndTime;

	@Override
	public Engine onLoadEngine()
	{	
		DisplayMetrics displayMetrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
		mCameraWidth = displayMetrics.widthPixels;
		mCameraHeight = displayMetrics.heightPixels;
		mCenterX = mCenterY = 0;
		
		mObjSynchronize = new Object();
		
		mCamera = new Camera(0, 0, mCameraWidth, mCameraHeight);
		
		return null;
	}
	
	@Override
	public Scene onLoadScene()
	{
		mEngine.registerUpdateHandler(new FPSLogger());

		mCenterX = mCameraWidth * 0.5f;
		mCenterY = mCameraHeight * 0.5f;
		
		return null;
	}

	@Override
	public boolean onCreateOptionsMenu(final Menu pMenu)
	{
		//pMenu.add(Menu.NONE, MENU_TRACE, Menu.NONE, "Start Method Tracing");
		return super.onCreateOptionsMenu(pMenu);
	}

	@Override
	public boolean onPrepareOptionsMenu(final Menu pMenu)
	{
		//pMenu.findItem(MENU_TRACE).setTitle(this.mEngine.isMethodTracing() ? "Stop Method Tracing" : "Start Method Tracing");
		return super.onPrepareOptionsMenu(pMenu);
	}

	@Override
	public boolean onMenuItemSelected(final int pFeatureId, final MenuItem pItem)
	{
		switch ( pItem.getItemId() ) {
			/*
			case MENU_TRACE:
				if ( this.mEngine.isMethodTracing() ) {
					this.mEngine.stopMethodTracing();
				} else {
					this.mEngine.startMethodTracing("AndEngine_" + System.currentTimeMillis() + ".trace");
				}
				return true;
			*/
			default:
				return super.onMenuItemSelected(pFeatureId, pItem);
		}
	}
}

/* end */
